package cn.com.java.controller;

import cn.com.java.core.HttpRes;
import cn.com.java.model.SysRoleMenu;
import cn.com.java.service.SysRoleMenuService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("SysRoleMenu")
@RequiredArgsConstructor
public class SysRoleMenuController {


    private final SysRoleMenuService sysRoleMenuService;

    /**
     * 查询所有记录
     *
     * @return 返回集合，没有返回空List
     */
    @RequestMapping("list")
    public List<SysRoleMenu> listAll() {
        return sysRoleMenuService.list();
    }


    /**
     * 根据主键查询
     *
     * @param id 主键
     * @return 返回记录，没有返回null
     */
    @RequestMapping("getById")
    public SysRoleMenu getById(Long roleId) {
        return sysRoleMenuService.getById(roleId);
    }

    /**
     * 新增，忽略null字段
     *
     * @param sysRoleMenu 新增的记录
     * @return 返回影响行数
     */
    @RequestMapping("insert")
    public int insert(@RequestBody SysRoleMenu sysRoleMenu) {
        return sysRoleMenuService.getBaseMapper().insert(sysRoleMenu);
    }

    /**
     * 修改，忽略null字段
     *
     * @param sysRoleMenu 修改的记录
     * @return 返回影响行数
     */
    @RequestMapping("update")
    public boolean update(@RequestBody SysRoleMenu sysRoleMenu) {
        return sysRoleMenuService.updateById(sysRoleMenu);
    }

    /**
     * 删除记录
     *
     * @param sysRoleMenu 待删除的记录
     * @return 返回影响行数
     */
    @RequestMapping("delete")
    public boolean delete(@RequestBody SysRoleMenu sysRoleMenu) {
        return sysRoleMenuService.removeById(sysRoleMenu.getRoleId());
    }

    @GetMapping("getSysRoleAndMenuByRoleId")
    public HttpRes getSysRoleAndMenuByRoleId(Long roleId){
        return HttpRes.OK(sysRoleMenuService.getSysRoleAndMenuByRoleId(roleId));
    }

    @GetMapping("getShowMenu")
    public HttpRes getShowMenu(){
        return HttpRes.OK(sysRoleMenuService.getShowMenu());
    }

}